home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <libc.h>
- #include <gl.h>
- #include <task.h>
- #include <device.h>
-
- #include "event.h"
- #include "percentDone.h"
-
- extern "C" int sginap(long);
-
-
- percentDone::percentDone(char * t, float (* f)(void *), void * d)
- {
- title = t;
- func = f;
- data = d;
-
- fatalError = 0;
- howFar = 0;
- howFarDisplayed = -1;
- doUpdate = 1;
- }
-
- percentDone::~percentDone()
- {
- delete_events(ANY, REDRAW, (int)window_id, (void *)ANY);
- delete_updates(&doUpdate, (void *)ANY);
-
- winclose(window_id);
- }
-
- void
- percentDone::start()
- {
- prefposition(getgdesc(GD_XPMAX) / 2 - 50,
- getgdesc(GD_XPMAX) / 2 + 50,
- getgdesc(GD_YPMAX) / 2 - 10,
- getgdesc(GD_YPMAX) / 2 + 10);
- foreground();
- window_id = winopen(title);
- ortho2(0, 1, 0, 1);
- update();
-
- add_event(ANY, REDRAW, (int)window_id,
- (void (*)())percentDone::redraw, this);
- add_update(&doUpdate, (void (*)())percentDone::update, this);
-
- task_id = taskcreate("percentDone",
- #ifdef _SYSTYPE_SVR4
- (void(*)(void *))percentDone::doIt,
- #else
- (void(*)())percentDone::doIt,
- #endif
- this, 0);
- }
-
-
- int
- percentDone::isDone()
- {
- if (fatalError)
- exit(1);
-
- return (howFar == 1.0);
- }
-
-
- void
- percentDone::wait()
- {
- while (! isDone())
- event();
- }
-
-
- void
- percentDone::doIt()
- {
- do {
- howFar = (*func)(data);
- if (howFar == -1) {
- fatalError = 1;
- taskdestroy((int)task_id);
- }
- } while (howFar != 1.0);
-
- taskdestroy((int)task_id);
- }
-
-
- void
- percentDone::update()
- {
- if (howFarDisplayed != howFar) {
- winset(window_id);
-
- color(14);
- rectf(0, 0, howFar, 1.0);
- color(7);
- rectf(howFar, 0.0, 1.0, 1.0);
-
- howFarDisplayed = howFar;
- }
- else
- sginap(33);
- }
-
-
- void
- percentDone::redraw()
- {
- winset(window_id);
- reshapeviewport();
- howFarDisplayed = -1;
-
- update();
- }
-